package com.thread.maipiao;

public class Ticket implements Runnable {
	private int ticks = 40;

	private synchronized void saleTicket() {
		if (ticks > 0) {
			System.out.println(Thread.currentThread().getName() + "卖出第" + ticks-- + "张票");
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	public void run() {
		while (ticks > 0) {
			saleTicket();

		}

	}

}
